/**
 * 
 */
package ui;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;

import model.*;

import exceptions.*;

/**
 * @author Anthares
 *
 */
public class ListingCommandePanel extends JPanel{
	private MainJFrame parent;
	private JButton cancelButton;
	private JTable comList;
	
	public ListingCommandePanel(MainJFrame par) throws PasIdentificationException, DatabaseErrorException, InvalidDataException{
		super();
		this.parent = par;
		
		this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY),"Listing des commande"));
		this.setLayout(new BorderLayout());
		
		JPanel southPanel = new JPanel();
			southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.LINE_AXIS));
			southPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 10));
			
			southPanel.add(Box.createHorizontalGlue());
			
			cancelButton = new JButton("Retour");
				cancelButton.addActionListener(new BoutonActionListener());
				parent.getRootPane().setDefaultButton(cancelButton);
			southPanel.add(cancelButton);
			
			southPanel.setAlignmentX(RIGHT_ALIGNMENT);
			
		this.add(southPanel,BorderLayout.SOUTH);
		
		comList = new JTable(new CommandeTableModel(0,0,0, null));
			comList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			JTableUtilities.packColumns(comList, 1);
			comList.setPreferredScrollableViewportSize(new Dimension(comList.getPreferredSize().width, 400));
			comList.setFillsViewportHeight(true);
		this.add(new JScrollPane(comList),BorderLayout.CENTER);
	}
	private class BoutonActionListener implements ActionListener{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent event) {
			if(event.getSource().equals(cancelButton)){
				parent.setContentPane(new BienvenuePanel());
				parent.pack();
				parent.setLocationRelativeTo(null);
				parent.setVisible(true);
			}

		}
	}
}
